package com.hera.process.config.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hera.base.util.FiltroDTO;
import com.hera.process.config.dao.SecGroupModuleDao;
import com.hera.process.config.domain.ParameterDetail;
import com.hera.process.config.service.SecGroupModuleService;
import com.hera.process.security.domain.SecGroupModule;
import com.hera.process.security.domain.SecGroupModulePK;
import com.hera.process.security.domain.SecurityGroup;

@Service("secgroupmodule")
public class SecGroupModuleServiceImpl implements SecGroupModuleService {

	static final Logger logger = Logger.getLogger(SecGroupModuleServiceImpl.class);
	
	@Autowired
	SecGroupModuleDao secgroupmoudelodao;
	
	@Override
	public SecGroupModule findById(SecGroupModulePK id) {
	return secgroupmoudelodao.findOne(id);
	}

	@Override
	public void update(SecGroupModule entity) {
		secgroupmoudelodao.save(entity);
	}

	@Override
	public void save(SecGroupModule entity) {
		secgroupmoudelodao.save(entity);
	}

	@Override
	public void delete(SecGroupModule entity) {
		secgroupmoudelodao.delete(entity);
	}

	@Override
	public List<SecGroupModule> findAll() {
	return secgroupmoudelodao.findAll();
	}

	@Override
	public List<SecGroupModule> findAll(FiltroDTO filtroDTO) {
	return secgroupmoudelodao.obtenerEntidadesPorFiltros(filtroDTO);
	}

	@Override
	public List<ParameterDetail> findAllModulosSiasignado(
			SecurityGroup securityGroup) {
		
		return secgroupmoudelodao.findAllModulosSiasignado(securityGroup.getIdSecurityGroup());
	}

	@Override
	public List<ParameterDetail> findAllModulosNoasignado(
			SecurityGroup securityGroup) {
		
		List codigos= secgroupmoudelodao.findAllModulosSiasignadoIds(securityGroup.getIdSecurityGroup());
		
		if(codigos.size()==0){
			codigos.add(new Long(-1));
		}
		
		return secgroupmoudelodao.findAllModulosNoasignado(codigos);
	}

}
